'use strict';
class Result {
  // constructor(code, msg, data){

  // }

  static success(res) {
    const data = {
      code: 0,
      msg: '成功',
      data: res,
    };
    return data;
  }

  static noDataSuccess() {
    const data = {
      code: 0,
      msg: '成功',
    };
    return data;
  }

  static fail() {
    const data = {
      code: -1,
      msg: '失败',
    };
    return data;
  }
  static warn(code, msg) {
    const data = {
      code,
      msg,
    };
    return data;
  }

  static result(code, msg, res) {
    const data = {
      code,
      msg,
      data: res,
    };
    return data;
  }

  static toInt(str) {
    if (!str) return 10;
    if (typeof str === 'number') return str;
    return parseInt(str, 10);
  }
}

module.exports = Result;
